<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Traffy</title>
</head>
<script type="text/javascript">
var getIncidentMessageUrl = 'http://api.traffy.in.th/apis/apitraffy.php?api=getIncident&key=AibgZsBJdV&appid=00001368&limit=5&format=JS&callback=sendIncident';
//For Intregration ... 
window.onload = function() {
	document.getElementById("message").innerHTML = "Connecting to TRAFFY ...";
	var url = getIncidentMessageUrl;
	var script = document.createElement('script');
	script.setAttribute('src', url);
	document.getElementsByTagName('head')[0].appendChild(script);
}

function sendIncident(t) {
	var message = "";
	for ( var obj in t) { 
		for ( var inO in t[obj].news) {
			var desc = t[obj].news[inO].description;
			var latitude;
			var longitude;
			if(t[obj].news[inO].location.point!=null){
				latitude = t[obj].news[inO].location.point.latitude;
				longitude = t[obj].news[inO].location.point.longitude;
			}else{
				latitude = 0.0;
				longitude = 0.0;
			}
			var type = t[obj].news[inO].type;
			var starttime = t[obj].news[inO].starttime;
			var endtime = t[obj].news[inO].endtime;
			var title = t[obj].news[inO].title;

			//var pointLatlng = new google.maps.LatLng(latitude, longitude);
			//addMakerForIncident(type, starttime, endtime, desc, title, pointLatlng);
			message += "("+latitude+","+longitude+"),";
		}
	}
	message = message.substring(0, message.length-1);
	submit(message);
}

function submit(message){
	var request = createXMLHttpRequest();
	
	request.open('post','./ajax?message='+message,false);
	request.send(null);
	var responseTxt = request.responseText;
	document.getElementById("message").innerHTML = responseTxt;
}

function createXMLHttpRequest(){
  // See http://en.wikipedia.org/wiki/XMLHttpRequest
  // Provide the XMLHttpRequest class for IE 5.x-6.x:
  if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
    throw new Error( "This browser does not support XMLHttpRequest.")
  };
  return new XMLHttpRequest();
}

</script>

<body>
	<div id="message"></div>
</body>
</html>